package com.fh.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.fh.dto.SysLog;
import com.fh.dto.SysUser;
import com.fh.web.constants.GlobalConstants;
import com.fh.web.service.PurviewService;
import com.fh.web.service.SysLogService;
import com.fh.web.vo.SubSysParamVo;

@Controller
@RequestMapping("")
public class loginController {
	// 打印logger日志
	private final Logger logger = LoggerFactory.getLogger(getClass());

	@Resource
	private SysLogService sysLogService;
	
	@Resource
	private PurviewService purviewService;
	
	
	@RequestMapping("")
	public ModelAndView loginSuccess(HttpServletRequest request) throws Exception{
		SysLog sysLog = (SysLog)request.getSession().getAttribute(GlobalConstants.SYS_LOG_LOGIN);
		if(sysLog != null){
			int addLog = sysLogService.addSysLog(sysLog);
			if (addLog > 0) {
				request.getSession().removeAttribute(GlobalConstants.SYS_LOG_LOGIN);
			}
		}
		//根据用户的权限展示菜单
		Map<String, Object> resMap = new HashMap<String, Object>();
		SysUser sysUser=(SysUser) SecurityUtils.getSubject().getSession().getAttribute(GlobalConstants.SYS_USER);
		List<SubSysParamVo> list = purviewService.getSubSysParam(sysUser.getUserId());
		resMap.put("list", list);
		logger.info("登录成功");
		return new ModelAndView("index", resMap);
	}
}
